#!/bin/bash

echo before comment
: <<'END'

ls
echo 'hello'



echo =====name=tom
name=tom
echo name
echo $name
echo ${name}test
echo test$name
echo $nametest




echo =====read from shell
# input
# aa bb
# aa
# aa bb cc
read var1 var2
echo var1=$var1
echo var2=$var2


echo =====new line 
echo a\nb # anb ==not work
printf "hello\nworld\n"
printf "%s \n%s abc\n" hello world


echo =====array
arr1[0]=x
arr1[1]=y
arr1[2]=3
echo ${arr1[0]}
echo ${arr1[*]}

arr2=(a b -9)
echo ${arr2[2]}
echo ${arr2[*]}



echo ===== enviroment variable
echo PWD=$PWD
echo HOME=$HOME
echo LOGNAME=$LOGNAME
echo SHELL=$SHELL
echo PATH=$PATH


echo ====="if statement"
# input
# 101
# -1
# 33
echo input a num 0~100:
read score
echo your score=$score
if [ $score -gt 100 ]; then # not use > or <
	printf "input value invalid: >100\n"
elif [ $score -lt 0 ]; then
	printf "value must > 0\n"
else
	printf "ok\n"
fi




echo ====="for loop"
for i in {1..5}
do 	echo "do sth with $i"
done

for i in 1 3 7
do 	echo "do sth with $i"
done

for i in {1..5} {10..15}
do 	echo "do sth with $i"
done

name=(wzq kjr wxl)
for i in ${name[*]}
do 	echo $i
done




echo ====="function"
function printName { # () is not necessary
	echo $1
	echo $2
}
printName wzq kjr wxl

function add() { # () is not necessary
	echo $1+$2 # add 3 4 => 3+4
	echo $(( $1+$2 )) # 7
	return $1+$2 
	# shell function cannot return
	# Although bash has a return statement, 
	# the very only thing you can specify with it is 
	# the function's exit status (a value between 0 and 255). 
	# So return is not what you want
}
add 3 4 


END
echo after comment






